﻿using Microsoft.AspNetCore.Components;
using Radzen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShowbusyDialogApp.Pages
{
    public partial class Index
    {
       private async Task ShowBusyDialog(bool withMessageAsString)
        {

            //Task.Run(async () =>
            //{
            //    // Simulate background task
            //    await getData();

            //    // Close the dialog
            //    dialogService.Close();
            //});


            Task task = new Task(()=>getData(1000));

            Task task1 = new Task( delegate { getData(1000); });

            Task task2 = new Task( () => { getData(1000); });            
                

            task1.Start();

            if (withMessageAsString)
            {
                await BusyDialog("load ... ...");
            }
            else
            {
                await BusyDialog();
            }
        }



        private async void getData(int ms)
        {
            await Task.Delay(ms);
            dialogService.Close();
        }

        private async Task<int> getSumData(int a, int b)
        {

            await Task.Delay(1000);
            dialogService.Close();
            return a + b;
        }




        // Busy dialog from string
        private async Task BusyDialog(string message)
        {
            await dialogService.OpenAsync("", ds =>
            {
                RenderFragment content = b =>
                {
                    b.OpenElement(0, "div");
                    b.AddAttribute(1, "class", "row");

                    b.OpenElement(2, "div");
                    b.AddAttribute(3, "class", "col-md-12");

                    b.AddContent(4, message);

                    b.CloseElement();
                    b.CloseElement();
                };
                return content;
            }, new DialogOptions() { ShowTitle = false, Style = "min-height:auto;min-width:auto;width:auto", CloseDialogOnEsc = false });
        }

       




}
}
